package com.yunzheng.studyLeaveSystem.modules.admin.show.students.dao.Impl;

import com.yunzheng.studyLeaveSystem.modules.admin.show.students.entity.leaver;
import com.yunzheng.studyLeaveSystem.modules.admin.show.students.dao.LeaveDao;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/*
*获取数据库变量为“name”的数据
*/
public class LeaveDaoImpl implements LeaveDao {

    @Override
    public List<leaver> queryInformation(String name) throws Exception {
        Connection connection = DBUtils.getCon();
        List<leaver> InformationList = new ArrayList<>();
        String sql = "select term,direction,leave_date,leave_class,reason from leaver where leaver_name =?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            leaver leaver = new leaver();
            leaver.setTerm(resultSet.getString("term"));
            leaver.setDirection(resultSet.getString("direction"));
            leaver.setLeave_date(resultSet.getString("leave_date"));
            leaver.setLeave_class(resultSet.getString("leave_class"));
            leaver.setReason(resultSet.getString("reason"));
            InformationList.add(leaver);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}